package com.leoandroid.tool.toolsbox.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.leoandroid.tool.toolsbox.PolicyToolActivity;
import com.leoandroid.tool.toolsbox.largeread.R;
import com.leoandroid.tool.toolsbox.largeread.fragment.MyFragment;


//隐私协议
public class ProtocolDialog extends Dialog {
    private OnProtocolDialogListener onProtocolDialogListener;
    private Context context;
    public ProtocolDialog(@NonNull Context context) {
        super(context);
        this.context = context;
        initView();
    }

    public ProtocolDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    protected ProtocolDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.context = context;
        initView();
    }

    private void initView(){
        setCanceledOnTouchOutside(false);
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_protocol_layout, null);
        setContentView(dialogView);

        dialogView.findViewById(R.id.agreen).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onProtocolDialogListener!=null){
                    onProtocolDialogListener.agree();
                }
            }
        });
        dialogView.findViewById(R.id.not_agreen).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onProtocolDialogListener!=null){
                    onProtocolDialogListener.refuse();
                }
            }
        });

        dialogView.findViewById(R.id.protocol_url_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PolicyToolActivity.class);
                intent.putExtra("TITLE","隐私政策");
                intent.putExtra("CONTENT", MyFragment.policyUrl);
                context.startActivity(intent);
            }
        });

        dialogView.findViewById(R.id.protocol_url_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PolicyToolActivity.class);
                intent.putExtra("TITLE","用户协议");
                intent.putExtra("CONTENT",MyFragment.userUrl);
                context.startActivity(intent);
            }
        });
    }

    public void setOnProtocolDialogListener(OnProtocolDialogListener onProtocolDialogListener){
        this.onProtocolDialogListener = onProtocolDialogListener;
    }


    public interface OnProtocolDialogListener{
        void agree();
        void refuse();
    }


}
